package com.elink.enginerring.video;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.common.BaseCo;
import com.elink.enginerring.common.Constant;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;
import com.elink.enginerring.user.entity.User;
import com.elink.enginerring.video.entity.Skill;
import com.elink.enginerring.video.entity.SkillFile;
import com.elink.enginerring.video.service.ISkillService;
@Controller
@RequestMapping("/view/skill")
@Api(value="工程技能体系接口")
public class SkillController {
	@Autowired
	private ISkillService  skillService;

	/**
	 * 分页获取工程技能体系
	 * @return
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ApiOperation(value = "获取工程技能体系", httpMethod = "GET",  notes = "分页获取工程技能体系")
	@ResponseBody
	public Map<String, Object>getList(@ModelAttribute @Valid BaseCo co ){
		DataSourceContextHolder.setDbType(DataSourceType.DBSKILL);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		return skillService.getList(co);
	}

	/**
	 * 增加工程技能体系--资料
	 * @param skillFile
	 * @return
	 */
	@RequestMapping(value = "/addFile", method = RequestMethod.POST)
	@ApiOperation(value = "增加工程技能体系--资料", httpMethod = "POST",  notes = "增加工程技能体系--资料")
	@ResponseBody
	public Map<String, Object>addFile(@ModelAttribute @Valid SkillFile skillFile){
		DataSourceContextHolder.setDbType(DataSourceType.DBSKILL);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		return skillService.addFile(skillFile);
	}
	
	/**
	 * 增加工程技能体系
	 * @param skill
	 * @return
	 */
	@RequestMapping(value = "/addSkill", method = RequestMethod.POST)
	@ApiOperation(value = "增加工程技能体系", httpMethod = "POST",  notes = "增加工程技能体系")
	@ResponseBody
	public Map<String, Object>addSkill(@ModelAttribute @Valid Skill skill,HttpSession session){
		DataSourceContextHolder.setDbType(DataSourceType.DBSKILL);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		User user = 	(User) session.getAttribute(Constant.su_in_session);
		skill.setCreateUserId(user.getUserId());
		return skillService.addSkill(skill);
	}
	
	
	/**
	 * 获取技能体系分类
	 * @param skill
	 * @return
	 */
	@RequestMapping(value = "/getCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取技能体系分类", httpMethod = "GET",  notes = "获取技能体系分类")
	@ResponseBody
	public Map<String, Object>getCategory(){
		DataSourceContextHolder.setDbType(DataSourceType.DBSKILL);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		return skillService.getCategory();
	}
}
